#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
	pid_t cpid = fork();
	if(cpid==0){
		//child process
		int count = 5;
		while(count--)
		{
			printf("child is running: %d.,ppid:%d\n",getpid(),getppid());
			sleep(1);
		}
		printf("chile quit!!!!\n");
		exit(123);//终止，退出码123
	}
	else if(cpid>0){
		int status = 0;

		pid_t ret = waitpid(-1,&status,0);

		int exit_code = (status >> 8 ) & 0xff;
		printf("father waits for success, ret: %d, exit code: %d\n", ret, exit_code);

	        if (exit_code == 0) printf("子进程把事情办成了！\n");
        	else printf("子进程没有把事情办成！\n");
	}
	else {

	}
	return 0;
}

